/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { BreakpointManager } from '../../hooks/BreakpointManager';
import { Breakpoints, HeightBreakpoint, WidthBreakpoint } from './types';

/**
 * 纵向断点区间定义（基于宽高比）：
 * - sm: 0 < sm < 0.8
 * - md: 0.8 <= md < 1.2
 * - lg: 1.2 <= lg
 */
export let heightBreakpointsMap: Breakpoints = {
  sm: 0.8,
  md: 1.2,
  lg: Infinity,
};

/**
 * 横向断点区间定义：
 * - xs: 0 < xs < 320
 * - sm: 320 <= sm < 600
 * - md: 600 <= md < 840
 * - lg: 840 <= lg < 1440
 * - xl: 1440 <= xl
 */
export let widthBreakpointsMap: Breakpoints = {
  xs: 320,
  sm: 600,
  md: 840,
  lg: 1440,
  xl: Infinity,
};

export const heightBreakpoints: HeightBreakpoint[] = ['sm', 'md', 'lg'];

export const widthBreakpoints: WidthBreakpoint[] = ['xs', 'sm', 'md', 'lg', 'xl'];

const breakpointManager = BreakpointManager.getInstance();

/**
 * 设置横向断点区间
 * @param newBreakpoints 新的横向断点区间
 */
export function setBreakpoints(newBreakpoints: Breakpoints): void {
  widthBreakpointsMap = { ...widthBreakpointsMap, ...newBreakpoints };
  breakpointManager.updateBreakpoint();
}

/**
 * 设置纵向断点区间
 * @param newBreakpoints 新的纵向断点区间
 */
export function setHeightBreakpoints(newBreakpoints: Breakpoints): void {
  heightBreakpointsMap = { ...heightBreakpointsMap, ...newBreakpoints };
  breakpointManager.updateBreakpoint();
}
